/**
 * Created by wangyan on 16/3/31.
 */
require('../models/local_repo.js');
var mongoose = require('mongoose');
var LocalRepo = mongoose.model('LocalRepo');


/**
 * 添加
 * @param body
 * @param callback
 */
exports.addLocalRepo = function(body, callback) {
	var info = {
		'fileName': body.fileName,
		'version': body.version,
		'other_info': body.other_info,
	};
	var localRepo = new LocalRepo(info);
	localRepo.save(callback);
};


/**
 * 删除
 * @param id
 * @param callback
 */
exports.deleteFile = function(id, callback) {
	LocalRepo.remove({_id:id}, callback);
};

/**
 * 更新版本号
 * @param fileName 文件名称 唯一标识
 * @param version 版本号
 * @param callback
 */
exports.updateLocalRepo = function(fileName, version, callback) {
	LocalRepo.update({
		fileName: fileName
	}, {
		version: version
	}, callback);
};

/**
 * 根据商品id查询
 * @param fileName 文件名称 唯一标识
 * @param callback
 */
exports.getLocalRepoByFileName = function(fileName, callback) {
	LocalRepo.findOne({
		fileName: fileName
	}, callback);
}

/**
 * 获取本地仓库中所有文件
 * @param callback
 */
exports.getLocalRepo = function(callback) {
	LocalRepo.find({},callback);
}